<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">

</head>
<body>
<div class="layui-fluid" style="margin-top: 50px;">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="hidden" th:value="${user.id}" name="id">
                <input th:value="${user.username}" type="text" name="username" required lay-verify="required"
                       placeholder="请输入姓名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">Email</label>
            <div class="layui-input-block">
                <input th:value="${user.email}" type="email" name="email" required lay-verify="required"
                       placeholder="请输入Email" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出生日期</label>
            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                <input th:value="${#dates.format(user.birthday, 'yyyy-MM-dd')}" type="text" class="layui-input"
                       name="birthday" id="birthday" placeholder="请输入出生日期" autocomplete="off">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" th:checked="${user.sex == '男'} ? true : false" name="sex" value="男" title="男">
                <input type="radio" th:checked="${user.sex == '女'} ? true : false" name="sex" value="女" title="女">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" th:checked="${user.state == 0} ? true : false" name="state" value="0" title="停用">
                <input type="radio" th:checked="${user.state == 1} ? true : false" name="state" value="1" title="用户"
                       checked>
                <input type="radio" th:checked="${user.state == 2} ? true : false" name="state" value="2" title="管理">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            </div>
        </div>
    </form>
</div>


<script th:src="@{/js/jquery-3.4.1.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            console.log(data.field)
            $.post("./", data.field, function (resp) {
               if(resp.code==0){
                   layer.msg("修改成功")
               }else {
                   layer.msg("修改失败")
               }
            })
            return false;
        });
    });

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#birthday' //指定元素
        });
    });
</script>
</body>
</html>